import { EditableFormInstance, EditableProTableProps } from "@ant-design/pro-table";
import { useRef, useState } from "react";


export const useEditableProTable = <T, P>(columns: EditableProTableProps<T, P>['columns']) => {
    const editFormRef = useRef<EditableFormInstance<T>>();
    const [editableKeys, setEditableRowKeys] = useState<React.Key[]>(() => []);
    const props: EditableProTableProps<T, P> = {
        columns: columns,
        editableFormRef: editFormRef,
        recordCreatorProps: false,
        editable: {
            type: 'multiple',
            editableKeys: editableKeys,
            onChange: setEditableRowKeys,
        }
    }
    return {
        editFormRef,
        props,
    }
}